//
// Created by jackal on 23-12-18.
//

#include "bag_dealer/Sample.h"

namespace DS {

    Sample::Sample(const std::string& token,
                   const long long& timestamp,
                   const std::string& scene_token,
                   const std::string& prev,
                   const std::string& next) :
                   token(token), timestamp(timestamp), scene_token(scene_token),
                   prev(prev), next(next)
                   { }
    Sample::Sample(const DS::Sample &sample)
    {
        token = sample.token;
        timestamp = sample.timestamp;
        scene_token = sample.scene_token;
        prev = sample.prev;
        next = sample.next;
    }
    Sample::Sample(const DS::Sample &&sample) noexcept
    {
        token = sample.token;
        timestamp = sample.timestamp;
        scene_token = sample.scene_token;
        prev = sample.prev;
        next = sample.next;
    }

    Sample& Sample::operator=(const DS::Sample &rhs)
    {
        if (this != &rhs)
        {
            token = rhs.token;
            timestamp = rhs.timestamp;
            scene_token = rhs.scene_token;
            prev = rhs.prev;
            next = rhs.next;
        }
        return *this;
    }

    Json::Value Sample::serialize()
    {
        Json::Value root;
        root["token"] = token;
        root["timestamp"] = timestamp;
        root["prev"] = prev;
        root["next"] = next;
        root["scene_token"] = scene_token;
        return root;
    }

    std::string Sample::get_prev() { return prev; }
    void Sample::set_next(const std::string &next) { this->next = next; }

    std::ostream& operator<<(std::ostream& out, const Sample& rhs)
    {
        out << "Sample: token = " << rhs.token << "\n"
            << "timestamp = " << rhs.timestamp << "\n"
            << "scene_token = " << rhs.scene_token << "\n"
            << "prev = " << rhs.prev << "\n"
            << "next = " << rhs.next << std::endl;
        return out;
    }


    SampleData::SampleData(const std::string token, const std::string sample_token,
                           const std::string calibrated_sensro_token, const std::string filename,
                           const std::string fileformat, int width, int height, long long timestamp,
                           const std::string prev, const std::string next) :
                           token(token), sample_token(sample_token),
                           calibrated_sensor_token(calibrated_sensro_token),
                           filename(filename), fileformat(fileformat),
                           width(width), height(height), timestamp(timestamp),
                           prev(prev), next(next) { }


    Json::Value SampleData::serialize() {
        Json::Value root;
        root["token"] = token;
        root["sample_token"] = sample_token;
        root["calibrated_sensor_token"] = calibrated_sensor_token;
        root["timestamp"] = timestamp;
        root["fileformat"] = fileformat;
        root["height"] = height;
        root["width"] = width;
        root["filename"] = filename;
        root["prev"] = prev;
        root["next"] = next;
        return root;
    }

    std::ostream& operator<<(std::ostream& out, const SampleData& rhs)
    {
        out << "Sample: token = " << rhs.token << "\n"
            << "sample_token = " << rhs.sample_token << "\n"
            << "calibrated_sensor_token = " << rhs.calibrated_sensor_token << "\n"
            << "filename = " << rhs.filename << "\n"
            << "fileformat = " << rhs.fileformat << "\n"
            << "width = " << rhs.width << "\n"
            << "height = " << rhs.height << "\n"
            << "timestamp = " << rhs.timestamp << "\n"
            << "prev = " << rhs.prev << "\n"
            << "next = " << rhs.next << std::endl;
        return out;
    }

    SampleList::~SampleList()
    {
        for (auto it = samples.begin(); it != samples.end(); it++)
        {
            delete *it;
        }
        for (auto it = sampledata.begin(); it != sampledata.end(); it++)
        {
            delete *it;
        }
    }

    void SampleList::dump(const std::string &fName)
    {

    }


} // DS